package com.s7.widget.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.s7.widget.R;

public class ImageUtils {

    /**
     * 加载图片
     * @param url
     * @param iv
     */
    public static void setImageUrl(Context context, String url, ImageView iv) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.image_no)
                .error(R.mipmap.image_no)
                .diskCacheStrategy(DiskCacheStrategy.NONE);
        Glide.with(context)
                .load(url)
                .apply(options)
                .into(iv);
    }

    /**
     * 加载图片
     * @param id
     * @param iv
     */
    public static void setImageUrl(Context context, int id, ImageView iv) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.image_no)
                .error(R.mipmap.image_no)
                .diskCacheStrategy(DiskCacheStrategy.NONE);
        Glide.with(context)
                .load(id)
                .apply(options)
                .into(iv);
    }
}
